package com.boomsecret.juc.atomic;

import java.util.concurrent.atomic.AtomicLongArray;

/**
 * @author wangjinliang on 2019/1/17.
 */
public class AtomicLongArrayDemo {
    public static void main(String[] args) {
        // 和AtomicLongArray差不多
        long[] array = {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L};
        AtomicLongArray atomicLongArray = new AtomicLongArray(array);
        System.out.println(atomicLongArray.length());

        System.out.println("-------------");
        atomicLongArray.set(0, 100);
        System.out.println(atomicLongArray.get(0));

        System.out.println("-------------");
        System.out.println(atomicLongArray.getAndUpdate(1, operand -> operand + 10));
        System.out.println(atomicLongArray.get(1));

        System.out.println("-------------");
        System.out.println(atomicLongArray.updateAndGet(2, operand -> operand + 10));
        System.out.println(atomicLongArray.get(2));

        System.out.println("-------------");
        System.out.println(atomicLongArray.getAndAccumulate(3, 88, (left, right) -> left + right));
        System.out.println(atomicLongArray.get(3));

        System.out.println("-------------");
        System.out.println(atomicLongArray.accumulateAndGet(4, 100, (left, right) -> left + right));
        System.out.println(atomicLongArray.get(4));
    }
}
